package cmd

import (
	"fmt"
	"kpt-dtm/config"
	"kpt-dtm/dep"
	"kpt-dtm/http"

	log "gitee.com/xuyiping_admin/pkg/logger/zaplog"

	"github.com/spf13/cobra"
)

// httpCmd represents the http command
var httpCmd = &cobra.Command{
	Use:   "http",
	Short: "start http server",
	Run: func(cmd *cobra.Command, args []string) {
		bootHTTPServer(config.Options())
	},
}

func bootHTTPServer(cfg *config.AppConfig) {
	dependency := dep.DIHttpDependency()
	log.Info("kpt-dtm: boot HTTP server")
	server := http.NewServer(
		http.ExportLogOption(),
		http.WithDependency(dependency),
		http.SetRouteOption(),
	)
	if err := server.Run(cfg.HTTPServerAddr); err != nil {
		fmt.Printf("HTTPServer run failed, err: %s", err)
	}
}
